package com.moyu.crowdsource.service;

import com.moyu.crowdsource.entity.Address;
import com.moyu.crowdsource.entity.AddressExample;
import com.moyu.crowdsource.mapperdao.AddressMapper;
import com.moyu.crowdsource.util.MyUUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AddressService {

    @Autowired
    AddressMapper addressMapper;

    public void addAddress(Address address){
        address.setAddressId(MyUUID.getUUID32());
        addressMapper.insertSelective(address);
    }

    public void updateAddress(Address address){
        addressMapper.updateByPrimaryKeySelective(address);
    }

    public void delAddress(String addressId){
        addressMapper.deleteByPrimaryKey(addressId);
    }

    public List<Address> getUserAddress(Integer userId){
        AddressExample example=new AddressExample();
        AddressExample.Criteria criteria=example.createCriteria();
        criteria.andUserIdEqualTo(userId);
        return addressMapper.selectByExample(example);
    }

    public Address getUserAddressByAddressId(String addressId){

        return addressMapper.selectByPrimaryKey(addressId);
    }

}
